package bigdata.hourglass.common.domain

import java.sql.Timestamp

import bigdata.hourglass.common.utils.ObjGenerator
import com.alibaba.fastjson.JSONObject

/**
 * @author leo.jie (weixiao.me@aliyun.com)
 * @organization DataReal
 * @version 1.0
 * @website https://www.jlpyyf.com
 * @date 2019/12/8 7:30 下午
 * @since 1.0
 */
object Bean {

  case class HourglassExecution(lSql: String = "",
                                var mode: String = SQLMode.L_SQL,
                                startTime: Timestamp = new Timestamp(System.currentTimeMillis),
                                var takeTime: Long = 0,
                                var success: Boolean = true,
                                var hdfsPath: String = "",
                                var user: String = "",
                                var data: String = "",
                                var dataType: String = ResultDataType.STRUCTURED_DATA,
                                var schema: String = "",
                                var variables: String = "[]",
                                var status: String = JobStatus.RUNNING,
                                var engineInfoAndGroupId: String = ""
                               ) {
    def toJSONObject: JSONObject = {
      ObjGenerator.newJson(Seq(("lSql", lSql), ("mode", mode), ("startTime", startTime), ("takeTime", takeTime),
        ("isSuccess", success), ("hdfsPath", hdfsPath), ("user", user), ("data", data), ("dataType", dataType),
        ("schema", schema), ("variables", variables), ("status", status), ("engineInfoAndGroupId", engineInfoAndGroupId)
      ): _*)
    }
  }

  case class LSql(mode: String, lSql: String, variables: String, token: String)
  case class HourglassEngine(engineId: Int, engineInfo: String)
  case class GetBatchResult(engineInfoAndGroupId: String)
  object JobStatus {
    val RUNNING = "RUNNING"
    val FINISH = "FINISH"
  }

  object SQLMode {
    val L_SQL = "lSql"
    val CODE = "code"
  }

  object ResultDataType {
    val ERROR_DATA = "errorData"
    val PRE_DATA = "preData"
    val STRUCTURED_DATA = "structuredData"
  }

}
